using System.Collections.Generic;
using FireStarter.Base;
using Firestarter.DB.Schema.BO;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using Habanero.Base;
using NUnit.Framework;
 
using Rhino.Mocks;

namespace Firestarter.DB_DomainModel.Logic.Test.DBChangesImporterTests
{
    [TestFixture]
    public class TestDBChangesImporter_ChangeTypeIsUpdate : TestBase
    {
        [Test]
        public void Test_ImportDBChanges_UpdatedDBTables_ShouldUpdateApproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBTable table = TestUtilsDBChangesImporter.CreateUpdatedTableWithMappedClass().ApproveForUpdate();
            DMClass mappedClass = table.GetMappedDMClass();
            //---------------Assert Precondition----------------
            Assert.That(mappedClass.ClassDescription, Is.Null);
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(mappedClass.ClassDescription, Is.EqualTo(table.TableComment));
            table.AssertIsBackToApprovedAndPendingChangeTypeIsNone();
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBTables_ShouldNotUpdateUnapproved()
        {
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBTable table = TestUtilsDBChangesImporter.CreateUpdatedTableWithMappedClass().UnApproveForUpdate();
            DMClass mappedClass = table.GetMappedDMClass();
            //---------------Assert Precondition----------------
            Assert.That(mappedClass.ClassDescription, Is.Null);
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(mappedClass.ClassDescription, Is.Null);
            table.AssertIsUnApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBProps_ShouldUpdateApproved()
        {
            //---------------Set up test pack-------------------
            DBColumn column = TestUtilsDBChangesImporter.CreateUpdatedColumnWithMappedProperty().ApproveForUpdate();
            DMProperty property = column.GetMappedDMProperty();

            IDBTypeToDMPropertyTypeMapper typeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            DMPropertyType expecteNewPropType = new DMPropertyType();
            typeMapper.Stub(t => t.GetDMPropertyType(column.DataType, 38)).Return(expecteNewPropType);
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter(typeMapper);

            //---------------Assert Precondition----------------
            Assert.That(property.Description, Is.Null);
            Assert.That(property.PropertyType, Is.Not.SameAs(expecteNewPropType));
            Assert.That(property.AutoIncrementing, Is.Not.EqualTo(column.IsAutoIncrementing));
            Assert.That(property.Compulsory, Is.Not.EqualTo(!column.Nullable));
            Assert.That(property.OrdinalPosition, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(column.Table.Database, (DMSolution) property.Class.Solution);
            //---------------Test Result -----------------------
            Assert.That(property.Description, Is.EqualTo(column.Comment));
            Assert.That(property.PropertyType, Is.SameAs(expecteNewPropType));
            Assert.That(property.AutoIncrementing, Is.EqualTo(column.IsAutoIncrementing));
            Assert.That(property.Compulsory, Is.EqualTo(!column.Nullable));
            Assert.That(property.OrdinalPosition, Is.EqualTo(1));
            column.AssertIsBackToApprovedAndPendingChangeTypeIsNone();
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBProps_ShouldNotUpdateUnapproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBColumn column = TestUtilsDBChangesImporter.CreateUpdatedColumnWithMappedProperty().UnApproveForUpdate();
            DMProperty property = column.GetMappedDMProperty();

            IDBTypeToDMPropertyTypeMapper typeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            DMPropertyType newPropertyType = new DMPropertyType();
            typeMapper.Stub(t => t.GetDMPropertyType(column.DataType, null)).Return(newPropertyType);
            //---------------Assert Precondition----------------
            Assert.That(property.Description, Is.Null);
            Assert.That(property.PropertyType, Is.Not.SameAs(newPropertyType));
            Assert.That(property.AutoIncrementing, Is.Not.EqualTo(column.IsAutoIncrementing));
            Assert.That(property.Compulsory, Is.Not.EqualTo(!column.Nullable));
            Assert.That(property.OrdinalPosition, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(column.Table.Database, (DMSolution) property.Class.Solution);
            //---------------Test Result -----------------------
            Assert.That(property.Description, Is.Null);
            Assert.That(property.PropertyType, Is.Not.SameAs(newPropertyType));
            Assert.That(property.AutoIncrementing, Is.Not.EqualTo(column.IsAutoIncrementing));
            Assert.That(property.Compulsory, Is.Not.EqualTo(!column.Nullable));
            Assert.That(property.OrdinalPosition, Is.EqualTo(1));
            column.AssertIsUnApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBPrimaryKey_ShouldUpdateApproved()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKey dbPrimaryKey =
                TestUtilsDBChangesImporter.CreateUpdatedPrimaryKeyWithMappedObjectIdentity().ApproveForUpdate();
            DBTable table = (DBTable)dbPrimaryKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();
            DMObjectIdentity objectIdentity = mappedClass.ObjectIdentity;

            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            //---------------Assert Precondition----------------
            Assert.That(objectIdentity, Is.Not.Null);
            Assert.AreEqual(1, objectIdentity.Properties.Count);
            Assert.IsFalse(objectIdentity.Properties.Contains(dbPrimaryKey.PrimaryKeyColumns[0].Column.GetMappedDMProperty()));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(mappedClass.ObjectIdentity, Is.SameAs(objectIdentity));
            Assert.AreEqual(1, objectIdentity.Properties.Count);
            Assert.IsTrue(objectIdentity.Properties.Contains(dbPrimaryKey.PrimaryKeyColumns[0].Column.GetMappedDMProperty()));
            dbPrimaryKey.AssertIsBackToApprovedAndPendingChangeTypeIsNone();
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBPrimaryKey_ShouldNotUpdateUnapproved()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKey dbPrimaryKey =
                TestUtilsDBChangesImporter.CreateUpdatedPrimaryKeyWithMappedObjectIdentity().UnApproveForUpdate();
            DBTable table = (DBTable)dbPrimaryKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();
            DMObjectIdentity objectIdentity = mappedClass.ObjectIdentity;

            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            //---------------Assert Precondition----------------
            Assert.That(objectIdentity, Is.Not.Null);
            Assert.AreEqual(1, objectIdentity.Properties.Count);
            Assert.IsFalse(objectIdentity.Properties.Contains(dbPrimaryKey.PrimaryKeyColumns[0].Column.GetMappedDMProperty()));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(mappedClass.ObjectIdentity, Is.SameAs(objectIdentity));
            Assert.AreEqual(1, objectIdentity.Properties.Count);
            Assert.IsFalse(objectIdentity.Properties.Contains(dbPrimaryKey.PrimaryKeyColumns[0].Column.GetMappedDMProperty()));
            dbPrimaryKey.AssertIsUnApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBKey_ShouldUpdateApproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBKey dbKey =
                TestUtilsDBChangesImporter.CreateUpdatedAlternateKeyWithMappedUniqueConstraint().ApproveForUpdate();
            DBTable table = (DBTable)dbKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();
            DMUniqueConstraint uniqueConstraint = mappedClass.UniqueConstraints[0];
            //---------------Assert Precondition----------------
            Assert.That(mappedClass.UniqueConstraints.Count, Is.EqualTo(1));
            Assert.That(uniqueConstraint, Is.Not.Null);
            Assert.IsFalse(uniqueConstraint.Properties.Contains(dbKey.KeyColumns[0].Column.GetMappedDMProperty()));
            Assert.That(table.Keys.Count, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, mappedClass.UniqueConstraints.Count);
            Assert.That(mappedClass.UniqueConstraints[0], Is.SameAs(uniqueConstraint));
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.IsTrue(uniqueConstraint.Properties.Contains(dbKey.KeyColumns[0].Column.GetMappedDMProperty()));
            dbKey.AssertIsBackToApprovedAndPendingChangeTypeIsNone();
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBKey_ShouldNotUpdateUnapproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBKey dbKey =
                TestUtilsDBChangesImporter.CreateUpdatedAlternateKeyWithMappedUniqueConstraint().UnApproveForUpdate();
            DBTable table = (DBTable)dbKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();
            DMUniqueConstraint uniqueConstraint = mappedClass.UniqueConstraints[0];
            //---------------Assert Precondition----------------
            Assert.That(mappedClass.UniqueConstraints.Count, Is.EqualTo(1));
            Assert.That(uniqueConstraint, Is.Not.Null);
            Assert.IsFalse(uniqueConstraint.Properties.Contains(dbKey.KeyColumns[0].Column.GetMappedDMProperty()));
            Assert.That(table.Keys.Count, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(mappedClass.UniqueConstraints.Count, Is.EqualTo(1));
            Assert.That(uniqueConstraint, Is.Not.Null);
            Assert.IsFalse(uniqueConstraint.Properties.Contains(dbKey.KeyColumns[0].Column.GetMappedDMProperty()));
            Assert.That(table.Keys.Count, Is.EqualTo(1));
            dbKey.AssertIsUnApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBForeignKey_ShouldUpdateApproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBForeignKey foreignKey =
                TestUtilsDBChangesImporter.CreateUpdatedForeignKeyWithMappedRelationship().ApproveForUpdate();
            DBTable parentTable = foreignKey.ParentTable;
            DMClass parentClass = parentTable.GetMappedDMClass();
            DMRelationship relationship = foreignKey.GetMappedDMRelationship();
            //---------------Assert Precondition----------------
            Assert.That(parentClass.OwnerRelationships.Count, Is.EqualTo(1));
            Assert.That(relationship, Is.Not.Null);
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsFalse(relationship.RelationshipProperties.Exists(relationshipProperty =>
                                                                      relationshipProperty.OwnerProperty ==
                                                                      foreignKey.ForeignKeyColumns[0].ParentColumn.GetMappedDMProperty()));
            Assert.That(parentTable.ForeignKeys.Count, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(parentTable.Database, (DMSolution) parentClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(parentClass.OwnerRelationships.Count, Is.EqualTo(1));
            Assert.That(parentClass.OwnerRelationships[0], Is.SameAs(relationship));
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsTrue(relationship.RelationshipProperties.Exists(relationshipProperty =>
                                                                     relationshipProperty.OwnerProperty ==
                                                                     foreignKey.ForeignKeyColumns[0].ParentColumn.GetMappedDMProperty()));
            foreignKey.AssertIsBackToApprovedAndPendingChangeTypeIsNone();
        }

        [Test]
        public void Test_ImportDBChanges_UpdatedDBForeignKey_ShouldNotUpdateUnapproved()
        {
            //---------------Set up test pack-------------------
            IDBChangesImporter importer = TestUtilsDBChangesImporter.CreateDBChangesImporter();
            DBForeignKey foreignKey =
                TestUtilsDBChangesImporter.CreateUpdatedForeignKeyWithMappedRelationship().UnApproveForUpdate();
            DBTable parentTable = foreignKey.ParentTable;
            DMClass parentClass = parentTable.GetMappedDMClass();
            DMRelationship relationship = foreignKey.GetMappedDMRelationship();
            //---------------Assert Precondition----------------
            Assert.That(parentClass.OwnerRelationships.Count, Is.EqualTo(1));
            Assert.That(relationship, Is.Not.Null);
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsFalse(relationship.RelationshipProperties.Exists(relationshipProperty =>
                                                                      relationshipProperty.OwnerProperty ==
                                                                      foreignKey.ForeignKeyColumns[0].ParentColumn.GetMappedDMProperty()));
            Assert.That(parentTable.ForeignKeys.Count, Is.EqualTo(1));
            //---------------Execute Test ----------------------
            importer.ImportDBChanges(parentTable.Database, (DMSolution) parentClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(parentClass.OwnerRelationships.Count, Is.EqualTo(1));
            Assert.That(relationship, Is.Not.Null);
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsFalse(relationship.RelationshipProperties.Exists(relationshipProperty =>
                                                                      relationshipProperty.OwnerProperty ==
                                                                      foreignKey.ForeignKeyColumns[0].ParentColumn.GetMappedDMProperty()));
            Assert.That(parentTable.ForeignKeys.Count, Is.EqualTo(1));
            foreignKey.AssertIsUnApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }


        [Test]
        public void Test_ImportDB_NewDBPrimaryKey_WhenSuccessful_ShouldReturnNoErrors()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKey dbPrimaryKey =
                TestUtilsDBChangesImporter.CreateUpdatedPrimaryKeyWithMappedObjectIdentity().ApproveForUpdate();
            DBTable table = (DBTable)dbPrimaryKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();

            List<string> errorMessages = new List<string>();
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithObjectIdentityImporterErrorMessages(dbToDMImporterFactory,
                                                                                           dbPrimaryKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(0, errors.Count);
        }

        [Test]
        public void Test_ImportDB_NewDBPrimaryKey_WhenHasErrors_ShouldReturnErrors()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKey dbPrimaryKey =
                TestUtilsDBChangesImporter.CreateUpdatedPrimaryKeyWithMappedObjectIdentity().ApproveForUpdate();
            DBTable table = (DBTable)dbPrimaryKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();

            List<string> errorMessages = new List<string> {TestUtilsShared.GetRandomString()};
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithObjectIdentityImporterErrorMessages(dbToDMImporterFactory,
                                                                                           dbPrimaryKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.That(errors.Count, Is.EqualTo(1));
            Assert.That(errors[0].BusinessObject, Is.SameAs(dbPrimaryKey));
            Assert.That(errors[0].Message, Is.EqualTo(errorMessages[0]));
            Assert.That(errors[0].Level, Is.EqualTo(ErrorLevel.Error));
            dbPrimaryKey.AssertIsApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDB_NewDBKey_WhenSuccessful_ShouldReturnNoErrors()
        {
            //---------------Set up test pack-------------------
            DBKey dbKey =
                TestUtilsDBChangesImporter.CreateUpdatedAlternateKeyWithMappedUniqueConstraint().ApproveForUpdate();
            DBTable table = (DBTable)dbKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();

            List<string> errorMessages = new List<string>();
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithUniqueConstraintImporterErrorMessages(dbToDMImporterFactory,
                                                                                             dbKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(0, errors.Count);
        }

        [Test]
        public void Test_ImportDB_NewDBKey_WhenHasErrors_ShouldReturnErrors()
        {
            //---------------Set up test pack-------------------
            DBKey dbKey =
                TestUtilsDBChangesImporter.CreateUpdatedAlternateKeyWithMappedUniqueConstraint().ApproveForUpdate();
            DBTable table = (DBTable)dbKey.Table;
            DMClass mappedClass = table.GetMappedDMClass();

            List<string> errorMessages = new List<string> {TestUtilsShared.GetRandomString()};
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithUniqueConstraintImporterErrorMessages(dbToDMImporterFactory,
                                                                                             dbKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(table.Database, (DMSolution) mappedClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errors.Count);
            Assert.That(errors[0].BusinessObject, Is.SameAs(dbKey));
            Assert.That(errors[0].Message, Is.EqualTo(errorMessages[0]));
            Assert.That(errors[0].Level, Is.EqualTo(ErrorLevel.Error));
            dbKey.AssertIsApprovedAndPendingChangeTypeIs(ChangeType.Update);
        }

        [Test]
        public void Test_ImportDB_NewDBForeignKey_WhenSuccessful_ShouldReturnNoErrors()
        {
            //---------------Set up test pack-------------------
            DBForeignKey foreignKey =
                TestUtilsDBChangesImporter.CreateUpdatedForeignKeyWithMappedRelationship().ApproveForUpdate();
            DBTable parentTable = (DBTable)foreignKey.ParentTable;
            DMClass parentClass = parentTable.GetMappedDMClass();

            List<string> errorMessages = new List<string>();
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithRelationshipImporterErrorMessages(dbToDMImporterFactory,
                                                                                         foreignKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(parentTable.Database, (DMSolution) parentClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(0, errors.Count);
        }

        [Test]
        public void Test_ImportDB_NewDBForeignKey_WhenHasErrors_ShouldReturnErrors()
        {
            //---------------Set up test pack-------------------
            DBForeignKey foreignKey =
                TestUtilsDBChangesImporter.CreateUpdatedForeignKeyWithMappedRelationship().ApproveForUpdate();
            DBTable parentTable = (DBTable)foreignKey.ParentTable;
            DMClass parentClass = parentTable.GetMappedDMClass();

            List<string> errorMessages = new List<string> {TestUtilsShared.GetRandomString()};
            IDBToDMImporterFactory dbToDMImporterFactory =
                TestUtilsDBChangesImporter.CreateStandardImporterFactoryStub();
            TestUtilsDBChangesImporter.SetupFactoryWithRelationshipImporterErrorMessages(dbToDMImporterFactory,
                                                                                         foreignKey, errorMessages);
            DBChangesImporter importer = new DBChangesImporter(dbToDMImporterFactory);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, errorMessages.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors = importer.ImportDBChanges(parentTable.Database, (DMSolution) parentClass.Solution);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errors.Count);
            Assert.That(errors[0].BusinessObject, Is.SameAs(foreignKey));
            Assert.That(errors[0].Message, Is.EqualTo(errorMessages[0]));
            Assert.That(errors[0].Level, Is.EqualTo(ErrorLevel.Error));
            foreignKey.AssertIsApprovedAndPendingChangeTypeIs(ChangeType.None);
        }
    }
}